﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderControl
{
    class OrderItem
    {
        //订单明细<商品序号，商品数量>
        public Dictionary<Item, int> orderItemList;
        public OrderItem()
        {
            orderItemList = new Dictionary<Item, int>();
        }
        public OrderItem(Item t, int number)
        {
            this.orderItemList.Add(t, number);
        }
        public void addItem(Item t, int number)
        {
            if (!Equals(t))
            {
                this.orderItemList.Add(t, number);
            }
            else
            {
                orderItemList[t] += number;
            }
        }
        //判断添加商品是否重复
        public override bool Equals(object obj)
        {
            Item t = obj as Item;
            foreach(Item i in orderItemList.Keys)
            {
                if(t.ItemNumber == i.ItemNumber)
                {
                    return true;
                }
            }
            return false;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override string ToString()
        {
            string s = "";
            foreach(Item i in this.orderItemList.Keys)
            {
                s += i.Name + "\t" + i.Price + "\t" + orderItemList[i] + "\n";
            }
            if(s == "")
            {
                s = "未查询到相关订单";
            }
            return s;
        }
    }
}
